<?php
$params = array_merge(
    require(__DIR__ . '/../../common/config/params.php'),
    require(__DIR__ . '/../../common/config/params-local.php'),
    require(__DIR__ . '/params.php'),
    require(__DIR__ . '/params-local.php')
);

return [
    'id' => 'app-backend',
    'basePath' => dirname(__DIR__),
    'controllerNamespace' => 'backend\controllers',
    'bootstrap' => ['log'],
    'modules' => [
        'user-management' => [
            'class' => 'webvimark\modules\UserManagement\UserManagementModule',

            // 'enableRegistration' => true,

            // Add regexp validation to passwords. Default pattern does not restrict user and can enter any set of characters.
            // The example below allows user to enter :
            // any set of characters
            // (?=\S{8,}): of at least length 8
            // (?=\S*[a-z]): containing at least one lowercase letter
            // (?=\S*[A-Z]): and at least one uppercase letter
            // (?=\S*[\d]): and at least one number
            // $: anchored to the end of the string

            //'passwordRegexp' => '^\S*(?=\S{8,})(?=\S*[a-z])(?=\S*[A-Z])(?=\S*[\d])\S*$',


            // Here you can set your handler to change layout for any controller or action
            // Tip: you can use this event in any module
            'on beforeAction' => function (yii\base\ActionEvent $event) {
                if ($event->action->uniqueId == 'user-management/auth/login') {
                    $event->action->controller->layout = '/login.php';
                    $event->action->controller->viewPath = '@backend/views/auth';
                } elseif ($event->action->uniqueId == 'user-management/user/index') {
                    $event->action->controller->layout = '/main.php';
//                    $event->action->controller->viewPath='@backend/views/user';
                };
            },
        ],
        'gridview' => [
            'class' => '\kartik\grid\Module'
            // enter optional module parameters below - only if you need to
            // use your own export download action or custom translation
            // message source
            // 'downloadAction' => 'gridview/export/download',
            // 'i18n' => []
        ],
        'datecontrol' => [
            'class' => 'kartik\datecontrol\Module',

            // format settings for displaying each date attribute (ICU format example)
//            'displaySettings' => [
//                Module::FORMAT_DATE => 'dd-MM-yyyy',
//                Module::FORMAT_TIME => 'HH:mm:ss a',
//                Module::FORMAT_DATETIME => 'dd-MM-yyyy HH:mm:ss a',
//            ],

            // format settings for saving each date attribute (PHP format example)
//            'saveSettings' => [
//                Module::FORMAT_DATE => 'php:U', // saves as unix timestamp
//                Module::FORMAT_TIME => 'php:H:i:s',
//                Module::FORMAT_DATETIME => 'php:Y-m-d H:i:s',
//            ],

            // set your display timezone
//            'displayTimezone' => 'Asia/Kolkata',

            // set your timezone for date saved to db
//            'saveTimezone' => 'UTC',

            // automatically use kartik\widgets for each of the above formats
            'autoWidget' => true,

            // use ajax conversion for processing dates from display format to save format.
            'ajaxConversion' => true,

            // default settings for each widget from kartik\widgets used when autoWidget is true
//            'autoWidgetSettings' => [
//                Module::FORMAT_DATE => ['type'=>2, 'pluginOptions'=>['autoclose'=>true]], // example
//                Module::FORMAT_DATETIME => [], // setup if needed
//                Module::FORMAT_TIME => [], // setup if needed
//            ],

            // custom widget settings that will be used to render the date input instead of kartik\widgets,
            // this will be used when autoWidget is set to false at module or widget level.
//            'widgetSettings' => [
//                Module::FORMAT_DATE => [
//                    'class' => 'yii\jui\DatePicker', // example
//                    'options' => [
//                        'dateFormat' => 'php:d-M-Y',
//                        'options' => ['class'=>'form-control'],
//                    ]
//                ]
//            ]
            // other settings
        ]
    ],
    'components' => [
        'request' => [
            'csrfParam' => '_csrf-backend',
        ],
//        'user' => [
//            'identityClass' => 'common\models\User',
//            'enableAutoLogin' => true,
//            'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true],
//        ],
        'user' => [
            'class' => 'backend\controllers\UserConfig',
//            'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => false],
            // Comment this if you don't want to record user logins
            'on afterLogin' => function ($event) {
                \webvimark\modules\UserManagement\models\UserVisitLog::newVisitor($event->identity->id);
            }
        ],
        'session' => [
            // this is the name of the session cookie used for login on the backend
            'name' => 'advanced-backend',
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'flushInterval' => 1,
            'targets' => [
                'db' => [
                    'class' => 'yii\log\DbTarget',
                    'logVars' => ['$_GET', '$_POST', '$_FILES',],
                    'exportInterval' => 1,
                    'levels' => ['error', 'warning'],
                    'categories' => [
                        'yii\db\*',
                        'yii\web\HttpException:*',
                    ],
                    'except' => [
                        'yii\web\HttpException:404',
                        'yii\web\HttpException:403',
                    ],
                ],
                'file' => [
                    'class' => 'yii\log\FileTarget',
                    'logVars' => [],
                    'levels' => ['info'],
                    'except' => [
                        'yii\web\*',
                        'yii\db\*',
                    ]
                ]
            ],
        ],
//        'errorHandler' => [
//            'class' => 'common\component\exception\ErrorHandler',
//        ],
        'urlManager' => require(__DIR__ . '/urlManager.php'),

    ],
    'params' => $params,
];
